package spring.core.examples.java.configuration;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.context.annotation.Scope;

import spring.core.examples.xml.Couple;

/**
 * Demononstrates how to provide Spring context meta data using Java. Note that
 * one of the couples configured in this example has scope prototype!
 */
@Configuration
@Profile("production")
public class CoupleConfiguration {

	/**
	 * Another Spring configuration that is used by this one. Not that the
	 * "@Import" annotation is not sufficient in this case.
	 */
	@Autowired
	PersonConfiguration personConfiguration;

	/**
	 * A couple bean with singleton scope. The scope of this couple is
	 * singelton. So calls to this method will always return the same instance
	 * of couple.
	 * 
	 * @return the couple
	 */
	@Bean
	public Couple aCouple() {
		return new Couple(personConfiguration.harry(),
				personConfiguration.elke());
	}

	/**
	 * Another couple bean with prototype scope. Calling this method will return
	 * a new instance each time.
	 * 
	 * @return the couple
	 */
	@Bean
	@Scope("prototype")
	public Couple anotherCouple() {
		return new Couple(personConfiguration.hein(),
				personConfiguration.elke());
	}

}
